<template>
	<view class="pad-30">
		<view class="font-40">错题集详情</view>

		<view v-for="(item,index) in list" :key="index" class="mar-top-70">
			<view>{{index+1}}.{{item.stem}}</view>
			<view class="mar-top-20">
				<view v-if="item.question_type == 1">题型：(单选题)</view>
				<view v-if="item.question_type == 2">题型：(多选题)</view>
				<view v-if="item.question_type == 3">题型：(判断题)</view>
			</view>
			<view v-for="(info,inx) in item.option" class="mar-top-20">
				<view :class="item.select.includes(inx)  ? 'u-error': ''">{{info}}</view>
			</view>
			<view class="mar-top-20">
				<text>您选择了：{{item.answer}}</text>
				<text class="u-success mar-left-40">正确答案：{{item.res.answer}}</text>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		reactive
	} from 'vue';

	// 接口引入
	import {
		errorInfo
	} from '/config/api.js';

	import {
		onLoad
	} from '@dcloudio/uni-app'

	let list = ref([])
	const getDataInfo = () => {
		errorInfo({
			test_id: infoId.value
		}).then(res => {
			list.value = res.data.map(item => {
				let arrText = item.res.answer.split(',');
				item.select = stringToNumber(arrText);
				return item;
			})
		})
	}

	// ABC 转 数字
	const stringToNumber = (str) => {
		return str.map(letter => {
			return (parseInt(letter, 36) - 10)
		});
	}

	const infoId = ref('');
	onLoad((param) => {
		infoId.value = param.id;
		getDataInfo()
	})
</script>

<style>

</style>